﻿
using System;
using Jayden.Dll.Web.HtmlControls.Generics;
namespace Jayden.Dll.Web.HtmlControls.Descriptions
{
	public abstract class HtmlControlDescription
	{
		public virtual bool CheckValidity(HtmlControl control)
		{
			if (control == null)
				throw new NullReferenceException("control is null.");
			if (!control.ServerRender)
				return false;
			if (!ControlType.IsAssignableFrom(control.GetType()))
				throw new Exception(string.Format("control must be of type {0}.", ControlType));
			if (control.Description != null && control.Description != this)
				throw new Exception(string.Format("invalid description, should be {0} and is {1}.", this, control.Description));
			return true;
		}

		public virtual string Description { get { return null; } }

		public abstract Type ControlType { get; }
		public HtmlControl New()
		{
			Type type = ControlType;
			if (type != null)
				return Activator.CreateInstance(type) as HtmlControl;
			return null;
		}
	}
}
